<?php
include "templates/page_start.tpl";
?>

<style>
    .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script>
    $(function() {
        function log( message ) {
            $( "<div/>" ).text( message ).prependTo( "#log" );
            $( "#log" ).scrollTop( 0 );
        }

        $( "#obj_name" ).autocomplete({
            source: "search.php?type=obj_name",

            minLength: 2,
            select: function( event, ui ) {
                log( ui.item ?
                    "Selected: " + ui.item.value + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value );
            }
        });
    });
</script>



<?php log_message('[china_find.tpl]' . GET_RECIVED); ?>
<form action='?section=china&action=find' method='GET'>
    <input type="hidden" name="section" value="china"></input>
    <input type="hidden" name="action" value="find"></input>
    <fieldset>
        <legend>Stammdaten</legend>

        <div class="ui-widget">
            <label for="obj_name">Name: </label>
            <input id="obj_name" name="obj_name" type="text" class="TextField ui-corner-all" value="<?php if (isset($data['obj_name']))
    echo $data['obj_name']; ?>"/>
        </div>



        <script>
            $(document).ready(function(){
                loadCategories();
	
            });
            function loadCategories(){
             
             
                $.getJSON("?section=cat&action=get",
                {},
                function(data) {
                        
                    var select = $('#obj_cat_id');
                    if(select.prop) {
                        var options = select.prop('options');
                    }
                    else {
                        var options = select.attr('options');
                    }
                    $('option', select).remove();
 
                    $.each(data, function(cat_count, category) { 
                        options[options.length] = new Option(category.cat_name, category.cat_id);
                    });
                });
            }

        </script>
        <div class="ui-widget">
            <label for='obj_cat_id'>Kategorie:</label>
            <select class="SelectField ui-corner-all" id="obj_cat_id" name="obj_cat_id"></select>

        </div>
    </fieldset>
    <fieldset>
        <script>
            $(function() {
                $( "input:submit, input:reset").button();
            });
        </script>

        <input type="hidden" name="cat_child" value="1" />
        <p>
            <input type="submit" value="Absenden" />
            <input type="reset" value="Zur&uuml;cksetzen" />
        </p>
    </fieldset>

</form>






<table id='obj_list'>
    <?php
    foreach ($data["objects"] as $obj_id => $object) {

        if (($obj_id == 0) || ($obj_id % 4 == 0))
            echo "<tr>\n";
        ?>
        <td id='obj_item'>
            <a href='?section=china&action=view&obj_id=<?php echo $object["obj_id"]; ?>'>
                <table>
                    <tr><td class="obj_item_img"><img src='<?php echo $object["obj_img_url"]; ?>'></td></tr>
                    <tr><td class="obj_item_name"><?php echo $object["obj_name"] ?></td></tr>
                </table>
             
            </a>
        </td>
   
        <?php
        if (($obj_id + 1) % 4 == 0) {
            echo "<tr/>\n";
        }
    }
    ?>
</table>
<?php
include "templates/page_end.tpl";
?>